home *** CD-ROM | disk | FTP | other *** search
- IF EXISTS (select * from sysobjects where
- name = 'sp_MSdeletefoldercontents' and type = 'P')
- DROP PROCEDURE sp_MSdeletefoldercontents
-
- raiserror(15339, -1, -1, 'sp_MSdeletefoldercontents')
- go
- --
- -- Name: sp_MSdeletefoldercontents
- --
- -- Description: This is a lighweight wrapper for deleting all files in the
- -- specified directory. This procedure is meant to be called by
- -- a remote publisher for deleting files in the distributor's
- -- context.
- --
- -- Parameter: @folder nvarchar(255) (mandatory)
- --
- -- Returns 0 - succeeded
- -- 1 - failed
- --
- -- Security: Only members of the sysadmin server role and members of the
- -- db_owner role of the distribution database can execute this function. This
- -- procedure is intended to be called through the distribution_admin remote
- -- login from remote publishers
- --
- create procedure sp_MSdeletefoldercontents (
- @folder nvarchar(255)
- )
- as
- begin
- set nocount on
-
- declare @command nvarchar(4000)
- declare @retcode int
-
- select @retcode = 0
- if len(@folder) = 0 or @folder is null
- begin
- return 0
- end
-
- -- Append '\*' to the given path
- if substring(@folder, len(@folder), 1) <> N'\'
- begin
- select @folder = @folder + N'\'
- end
-
- select @folder = @folder + '*'
-
- if (platform() & 0x1) = 0x1
- begin
- select @command = 'del /q /f "' + fn_escapecmdshellsymbolsremovequotes(@folder) collate database_default + '"'
- end
- else
- begin
- -- Win9x 'del' command does not support the /q and /f switches
- select @command = 'del "' + fn_escapecmdshellsymbolsremovequotes(@folder) collate database_default + '.*"'
- end
-
- exec @retcode = master..xp_cmdshell @command, no_output
- return @retcode
-
- end
- go
-
- IF EXISTS (select * from sysobjects where
- name = 'sp_MSreplremoveuncdir' and type = 'P')
- DROP PROCEDURE sp_MSreplremoveuncdir
- GO
-
- CREATE PROCEDURE sp_MSreplremoveuncdir
- @dir nvarchar(260)
- as
-
- set nocount on
-
- declare @retcode int
- declare @local_dir nvarchar(260)
- declare @cmd nvarchar(1000)
- declare @machinename sysname
- /*
- ** We have to convert UNC to drive, otherwise will get 'Access denied' error in xp_cmdshell
- */
- select @machinename = convert(sysname, SERVERPROPERTY('machinename'))
- EXEC @retcode = master.dbo.sp_MSunc_to_drive @unc_path = @dir,
- @local_server = @machinename, @local_path = @local_dir OUTPUT
- IF @retcode <> 0 or @@ERROR <> 0
- RETURN(1)
-
- /*
- ** Delete directory in the distributor's directory.
- ** On Win9x, we have to use deltree instead
- */
- declare @platform_nt int
- select @platform_nt = 0x1
- IF (( platform() & @platform_nt = @platform_nt))
- BEGIN
- SELECT @cmd = 'if exist "' + fn_escapecmdshellsymbolsremovequotes(@local_dir) collate database_default + '" rmdir /S /Q ' + '"' + fn_escapecmdshellsymbolsremovequotes(@local_dir) collate database_default + '"'
- END
- ELSE
- BEGIN
- -- Don't need if exists check on Win9x but we do need
- -- to remove the trailing slash
- IF SUBSTRING(@local_dir, LEN(@local_dir), 1) = N'\'
- BEGIN
- SELECT @local_dir = LEFT(@local_dir, LEN(@local_dir)-1)
- END
- SELECT @cmd = 'deltree /Y ' + '"' + fn_escapecmdshellsymbolsremovequotes(@local_dir) collate database_default + '"'
- END
-
- EXECUTE @retcode = master..xp_cmdshell @cmd, NO_OUTPUT
- IF @retcode <> 0 or @@ERROR <> 0
- begin
- raiserror(20015, 16, -1, @dir)
- RETURN(1)
- end
- go
-
-